package com.stormragetech.sylwanas.process;

import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;

/**
 * description: //TODO
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Data
@Log4j2
abstract class MQBuilder {

    // MQ access params
    //
    private String host;
    private int port;
    private String username;
    private String password;

    // init params
    // 0: all | 1: sender only | 2: consumer only
    private int module = 0;

    // serialize type
    // protobuf | json
    //
    private String converter = "json";

    // init dead letter queue
    // true: init | false: not init
    //
    private boolean deadletter = true;

    // record result
    // true: record | false: not record
    //
    private boolean record = false;

    // reply timeout
    private long timeout = 5000L;

    // sender info
    //
    private boolean sendSync = false;           // syncsend  true: on | false: off
    private int sendRetryCount = 0;             // consume failed retry count
    private long sendTimeout = 0L;              // send message time out
    private long sendIntervalMils = 1000L;         // send message interval
    private long sendRetryIntervalMils = 6000L;    // failed retry interval

    // consumer info
    //
    private int consumeRetryCount = 0;          // consume failed retry count
    private int consumeThreadCount = 5;         // consume execute thread count
    private long consumeIntervalMils = 1000L;      // consume interval
    private long consumeRetryIntervalMils = 1000L; // consume retry interval

    private ConnectionFactory factory;


    ConnectionFactory initFactory(String host, int port, String username, String password) {
        CachingConnectionFactory connectionFactory = new CachingConnectionFactory(host, port);
        connectionFactory.setUsername(username);
        connectionFactory.setPassword(password);
        connectionFactory.setPublisherConfirms(true); // enable confirm mode
        return connectionFactory;
    }

//    public RetryCache initCache(){
//        RetryCache cache = new RetryCache();
//    }


}
